package servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import pojo.GuestDto;
import pojo.Manager;
import server.CheckInServer;

public class CheckInServlet extends HttpServlet {
	public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("checkInServlet");
		String guestName = "guestName";
		String sex = "sex";
		String roomType = "roomType";
		String tel = "tel";
		String identity = "identity";
		String roomNum = "roomNum";
		String perDay = "PerDay";
		String day;
		
		HttpSession session = request.getSession();
		GuestDto gue = (GuestDto)session.getAttribute("fistGuest");
		List<GuestDto> list = new ArrayList<GuestDto>();
		list.add(gue);
		
		for(int i=1;i<=5;i++){
			GuestDto guset = new GuestDto();
			String guestName1 = "guestName"+i;
			String sex1 = "sex"+i;
			String tel1 = "tel"+i;
			String identity1 = "identity"+i;
			if(request.getParameter(guestName1)!=null && !request.getParameter(guestName1).isEmpty()){
				System.out.println("guestName1 = "+guestName1);
				guset.day = gue.day;
				guset.name = request.getParameter(guestName1);
				System.out.println(guset.name);
				guset.sex = request.getParameter(sex1);
				guset.roomNum = gue.roomNum;
				guset.roomType = gue.roomType;
				guset.tel = request.getParameter(tel1);
				guset.perDay = gue.perDay;
				guset.id = request.getParameter(identity1);
				guset.paid = gue.paid;
				list.add(guset);
			}
			else{
				break;
			}
		}
		
		CheckInServer checkServer = new CheckInServer();
		
		Manager manager = (Manager)session.getAttribute("inof");
		checkServer.checkIn(list, manager.num);
		
		response.sendRedirect("/hotel/checkIn.jsp");
		
	}
}
